const eventNames = [
  'API:UN_AUTH',
  'API:BAD_REQUEST',
  'API:SUCCESS_REQUEST',
  'API:LOADING',
  'API:ERROR_REQUEST',
  'API:UPLOAD_SUCCESS',
  'API:UPLOAD_FAIL',
] as const;

type EventNames = (typeof eventNames)[number];

class eventEmitter {
  private listeners: Record<EventNames, Set<Function>> = {
    'API:UN_AUTH': new Set(),
    'API:BAD_REQUEST': new Set(),
    'API:SUCCESS_REQUEST': new Set(),
    'API:LOADING': new Set(),
    'API:ERROR_REQUEST': new Set(),
    'API:UPLOAD_SUCCESS': new Set(),
    'API:UPLOAD_FAIL': new Set(),
  };

  on(eventName: EventNames, listener: Function) {
    this.listeners[eventName].add(listener);
  }

  emit(eventName: EventNames, ...args: any[]) {
    this.listeners[eventName].forEach((listener) => listener(...args));
  }
}

export default new eventEmitter();
